import functools

from flask import session, g


def do_index_class(index):
    if index == 0:
        return 'first'
    elif index == 1:
        return 'second'
    elif index == 2:
        return 'third'
    else:
        return ''



def user_is_login(f):
    """
    判断用户是否登录
    :param f:
    :return:
    """
    @functools.wraps(f)
    def wrapper(*args,**kwargs):
        # 获取到当前登录用户的id
        user_id = session.get("user_id")
        # 通过id获取用户信息
        user = None
        if user_id:
            from info.models import User
            user = User.query.get(user_id)

        g.user = user
        return f(*args, **kwargs)
    return wrapper
